package wangjg.xuexiban.vo;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * @author wangjg
 *
 */
public class JsonResponse extends HashMap<String,Object> {
	private static final long serialVersionUID = 1L;
	
	private static final String ATTRIBUTE_STATUS = "code";
	private static final String ATTRIBUTE_MESSAGE = "message";
	private static final String ATTRIBUTE_DATA = "data";
	
	public JsonResponse() {
		
	}
	
	public boolean noError(){
		return this.getMessage()==null;
	}
	
	public JsonResponse(String status, String message) {
		this.setAttribute(ATTRIBUTE_STATUS, status);
		this.setAttribute(ATTRIBUTE_MESSAGE, message);
	}

	public String getStatus(){
		return this.getAttribute(ATTRIBUTE_STATUS);
	}

	public String getMessage() {
		return this.getAttribute(ATTRIBUTE_MESSAGE);
	}

	public void setMessage(String message) {
		this.setAttribute(ATTRIBUTE_MESSAGE, message);
	}

	public void setStatus(String status) {
		this.setAttribute(ATTRIBUTE_STATUS, status);
	}

	public Object getData() {
		return this.get(ATTRIBUTE_DATA);
	}

	public void setData(Object data) {
		super.put(ATTRIBUTE_DATA, data);
	}
	
	public String getAttribute(String name){
		return get(name)==null?null:get(name).toString();
	}
	
	public void setAttribute(String name, String value){
		super.put(name, value);
	}
	
	/**
	 * 约束一下，必须调用set方法赋值
	 */
	public Object put(String key, Object val){
		throw new RuntimeException();
	}
	
	/**
	 * 约束一下，必须调用set方法赋值
	 */
	public void putAll(Map m) {
		throw new RuntimeException();
	}
}
